//
//  YBMineSettingVC.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/6/9.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift
import EachNavigationBar

class YBMineSettingVC: BaseVC {
    
    enum RowType: Int {
        case resolution = 0
        case fps
        case videoBitrate
        
        var des: String {
            switch self {
            case .resolution: return "分辨率"
            case .fps: return "FPS"
            case .videoBitrate: return "视频比特率"
            }
        }
    }
    
    private var sections: [[RowType]] = [
        [.resolution, .fps, .videoBitrate]
    ]
    
    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()

        navigation.item.title = "设置"
        view.backgroundColor = .lightGray248Dark27
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.top.equalTo(kNavigationBarHeight)
            make.left.bottom.right.equalToSuperview()
        }
        
    }
    
    // MARK: - lazy
    private lazy var tableView: UITableView = {
        let tv = UITableView(frame: .zero, style: .grouped)
        tv.backgroundColor = .clear
        tv.estimatedRowHeight = 44
        tv.separatorStyle = .none
        tv.rowHeight = UITableView.automaticDimension
        tv.delegate = self
        tv.dataSource = self
        tv.showsVerticalScrollIndicator = false
        tv.register(cellWithClass: YBMineSettingCell.self)
        return tv
    }()
    
}

// MARK: - UITableView代理
extension YBMineSettingVC: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return sections.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sections[section].count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let sec = sections[indexPath.section]
        let row = sec[indexPath.row]
        let cell = tableView.dequeueReusableCell(withClass: YBMineSettingCell.self, for: indexPath)
        cell.kTitleLabel.text = row.des
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: false)
        let vc = YBConfigSettingVC()
        self.navigationController?.pushViewController(vc)
    }
    
}
